<?php
namespace app\admin\controller;

use app\admin\module\LoginModule;
use app\BaseController;
use app\Request;
use think\Exception;

class  Login extends BaseController{

    public function index(){
        echo "this is login controller";
    }

    public function info(Request $request){
        $res = [];
        $res['userinfo'] = LoginModule::info($request->uid);
        $res['menu'] = LoginModule::menu($request->uid);
        $res['permission'] = LoginModule::permission($request->uid);
        return $this->success("获取成功",$res);
    }

    public function userinfo(Request $request){
        return $this->success('获取成功',LoginModule::info($request->uid));
    }

    public function menu(Request $request){
        return $this->success('获取成功',LoginModule::menu($request->uid));
    }

    public function permission(Request $request){
        return $this->success("获取成功",LoginModule::permission($request->uid));
    }

    public function login(Request $request){
        $username = $request->param("username");
        $password = $request->param("password");

        if(empty($username) || empty($password)){
            throw new Exception("请输入用户名和密码");
        }

        $token = LoginModule::login($username,$password);
        return $this->success('登录成功',['token'=>$token]);
    }

    public function logout(Request $request){
        LoginModule::logout($request->uid);
        return $this->success("操作成功");
    }

}